package com.zyy.admin.controller;

import com.zyy.admin.entity.LabelUser;
import com.zyy.admin.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *@author zhangyangyang
 *@createTime 2023419 10:31
 *@description 管理后台管理接口
 */
@RestController
@RequestMapping("admin")
//@PreAuthorize("hasRole('ROLE_ADMIN')")
public class AdminController {

    @Autowired
    private DataService dataService;

    @RequestMapping("checkUsers")
    @ResponseBody
    @PreAuthorize("hasAuthority(T(com.zyy.admin.config.security.PermissionEnum).ROLE_ADMIN)")
    public String checkUsers() {
        return "测试-如果你看见这句话，说明你访问checkUsers权限";
    }

    @RequestMapping("checkRoles")
    @ResponseBody
    @PreAuthorize("hasAuthority(T(com.zyy.admin.config.security.PermissionEnum).ROLE_ADMIN)")
    public String checkRoles() {
        return "如果你看见这句话，说明你访问checkRoles权限";
    }

    @RequestMapping("getAllUser")
    @ResponseBody
    @PreAuthorize("hasAuthority(T(com.zyy.admin.config.security.PermissionEnum).ROLE_ADMIN)")
    List<LabelUser> getAllUser(){
        return dataService.getAllUser();
    }

}
